# coding: utf-8

import os
import time

__author__ = 'weixin.yuan'


TOMCAT_HOME = '/Library/tomcat/webapps'
report_path = TOMCAT_HOME + '/report'  # mac 服务器tomcat地址
train_log_path = TOMCAT_HOME + '/log/train'  # 运行时日志路径
appium_log_path = TOMCAT_HOME + '/log/appium'  # appium日志路径


def delete_file(path):
    print('开始清理%s下历史文件' % path)
    time_flag = time.time() - 3600 * 24 * 7  # 获取删除时间节点（7天前）
    list_dir = os.listdir(path)  # 获取文件列表
    for f in list_dir:
        f = path + '/' + f
        create_time = os.path.getctime(f)  # 获取创建时间
        if create_time < time_flag:
            os.remove(f)  # 小于删除节点，即删除
    print('清理完成%s下历史文件' % path)


if __name__ == '__main__':
    delete_file(report_path)
    delete_file(appium_log_path)
    delete_file(train_log_path)

